import { ShopStatus } from "@/enums";
import { Tag } from "antd";
import { Link } from "react-router-dom";
import styles from "./index.module.less";

export const SEARCH_COLUMNS = [
	{
		type: "input",
		placeholder: "请输入店铺关键词",
		name: "keyword"
	},
	// {
	// 	type: "input",
	// 	placeholder: "请输入店铺ID",
	// 	name: "name"
	// },

	{
		type: "select",
		placeholder: "请选择店铺状态",
		name: "shop_status",
		request: async () => {
			return ShopStatusList;
		}
	}
];

export const ShopStatusList = [
	{
		label: "营业中",
		value: ShopStatus.OPEN,
		colorInfo: {
			bgColor: "#E5FDE9",
			fontColor: "#0B801E"
		}
	},
	{
		label: "审核中",
		value: ShopStatus.AUDIT,
		colorInfo: {
			bgColor: "#FFF8ED",
			fontColor: "#DE6700"
		}
	},
	{
		label: "下架",
		value: ShopStatus.DOWN,
		colorInfo: {
			bgColor: "#F3F4F7",
			fontColor: "#7E7E7E"
		}
	},
	{
		label: "审核拒绝",
		value: ShopStatus.REFUSE,
		colorInfo: {
			bgColor: "#FFF8ED",
			fontColor: "#DE6700"
		}
	}
];

export const TABLE_COLUMNS = [
	{
		title: "店铺名称",
		dataIndex: "shop_name",
		width: 200,
		fixed: "left",
		className: styles.name,
		render: (_, record) => (
			<Link to={`/merchant/info`} state={{ data: record, isView: true }}>
				{record.shop_name}
			</Link>
		)
	},
	// {
	// 	title: "店铺ID",
	// 	dataIndex: "a",
	// 	width: 140,
	// 	fixed: "left"
	// },
	{
		title: "商品个数",
		dataIndex: "product_num",
		width: 140
	},
	{
		title: "联系人",
		dataIndex: "contacter",
		width: 140
	},
	{
		title: "发/退货地址",
		dataIndex: "a",
		width: 200,
		render: (_, record) => (
			<Link to={`/merchants/address?shop_id=${record.shop_id}&name=${record.shop_name}`}>
				{record?.return_addresses_num || record?.send_addresses_num ? (
					`${record?.send_addresses_num ?? 0} / ${record?.return_addresses_num ?? 0} `
				) : (
					<span style={{ color: "#E82F2F" }}>未设置</span>
				)}
			</Link>
		)
	},

	{
		title: "创建时间",
		dataIndex: "created_at",
		width: 160
	},
	{
		title: "状态",
		dataIndex: "shop_status",
		width: 160,
		render: (_, record) => {
			const target = ShopStatusList.find(item => item.value === record.shop_status);

			if (!target) return "-";
			return (
				<Tag color={target?.colorInfo?.bgColor} style={{ color: target?.colorInfo?.fontColor }}>
					{target?.label ?? "-"}
				</Tag>
			);
		}
	}
];
